<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- K 次操作后最大化顶端元素 -->
    <script>
      var maximumTop = function (nums, k) {
        if (k === 0) {
          return nums[0]
        }
        if (k === 1) {
          return nums[1] ?? -1
        }
        if (nums.length === 1 && k % 2 === 1) {
          return -1
        }
        let slice = nums.slice(0, k - 1)
        return Math.max(...slice, nums[k] || 0)
      }
      console.log(maximumTop([5, 2, 2, 4, 0, 6], 4))
    </script>
  </body>
</html>
